<!--
 * @Author: cheung0
 * @Date: 2021-11-20 14:24:26
-->
<template>
  <el-form
    status-icon
    label-width="100px"
    class="login-container"
    @keyup.enter.native="doLogin"
  >
    <h3 class="login_title">校园失物招领后台登录</h3>
    <el-form-item label="账户" autocomplete="off" label-width="80px">
      <el-input
        type="input"
        :clearable="true"
        v-model="table.userName"
        autocomplete="off"
        placeholder="请输入账号"
      ></el-input>
    </el-form-item>
    <el-form-item label="密码" label-width="80px">
      <el-input
        type="password"
        :learable="true"
        :show-password="true"
        v-model="table.password"
        autocomplete="off"
        placeholder="请输入密码"
      ></el-input>
    </el-form-item>
    <el-form-item class="longin_submit">
      <el-button type="primary" @click="doLogin" class="longin_submit"
        >登录
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { createNamespacedHelpers } from "vuex";

const { mapActions: loginMapActions } = createNamespacedHelpers("userlogin");
export default {
  name: "Login",
  data() {
    return {
      table: {
        userName: "",
        password: "",
      },
    };
  },
  methods: {
    ...loginMapActions(["login", "isLogin"]),
    async doLogin() {
      await this.login(this.table);
    },
  },
  async mounted() {
    if (await this.isLogin()) {
      location.href = "#/back/home";
    }
  },
};
</script>

<style>
.login-container {
  border-radius: 15px; /*圆角*/
  background-clip: padding-box; /*背景被裁剪到内边距框*/
  margin: 180px auto; /*边界 距上180px 左右居中*/
  width: 350px; /*表单宽度*/
  padding: 35px 35px 15px 35px; /*填充*/
  background: #fff;
  border: 1px solid #eaeaea; /*边框*/
  box-shadow: 0 0 25px #cac6c6; /*隐形*/
}

.login_title {
  margin: 0px auto 40px auto; /*上边界0 下边边界40 左右居中*/
  text-align: center; /*上面仅是标签居中 这里是文字居中*/
  color: #505458;
}

.longin_submit {
  margin: 10px auto 0 auto; /*上边界10 下边边界40 左右居中*/
}
</style>
